package com.jyw.web.controller.system;


import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import com.jyw.system.domain.dto.SysDeptIpAddressBatchAddDto;
import com.jyw.system.domain.dto.SysDeptIpAddressEditDto;
import com.jyw.system.domain.dto.SysDeptIpAddressPageDto;
import com.jyw.system.domain.vo.SysDeptIpAddressVo;
import com.jyw.system.service.ISysDeptIpAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 科室IPController
 *
 * @author zhangcheng
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/system/ipAddress")
@Api(tags = "系统科室IP")
public class SysDeptIpAddressController extends BaseController {
    @Resource
    private ISysDeptIpAddressService sysDeptIpAddressService;

    /**
     * 根据科室ID查询科室IP列表
     */
    @GetMapping(value = "/getIpAddressByDeptId")
    @ApiOperation("根据科室ID查询科室IP列表")
    public CommonResult<List<SysDeptIpAddressVo>> getIpAddressByDeptId(Long deptId) {
        return CommonResult.success(sysDeptIpAddressService.getIpAddressByDeptId(deptId));
    }

    /**
     * 查询科室IP列表
     */
    @GetMapping("/list")
    @ApiOperation("查询科室IP列表")
    public TableDataInfo<SysDeptIpAddressVo> list(SysDeptIpAddressPageDto pageDto) {
        startPage();
        List<SysDeptIpAddressVo> list = sysDeptIpAddressService.getIpAddressList(pageDto);
        return getDataTable(list);
    }


    /**
     * 获取科室IP详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取科室IP详细信息")
    public CommonResult<SysDeptIpAddressVo> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(sysDeptIpAddressService.getInfoById(id));
    }

    /**
     * 新增科室IP
     */
    @Log(title = "科室IP", businessType = BusinessType.INSERT)
    @PostMapping(value = "sysBatchAdd")
    @ApiOperation("新增科室IP")
    @PreAuthorize("@ss.hasPermi('system:dept:ip:add')")
    public CommonResult add(@RequestBody @Valid SysDeptIpAddressBatchAddDto batchAddDto) {
        sysDeptIpAddressService.sysBatchAdd(batchAddDto);
        return CommonResult.success();
    }

    /**
     * 修改科室IP
     */
    @Log(title = "科室IP", businessType = BusinessType.UPDATE)
    @PutMapping(value = "sysEdit")
    @ApiOperation("修改科室IP")
    @PreAuthorize("@ss.hasPermi('system:dept:ip:edit')")
    public CommonResult edit(@RequestBody @Valid SysDeptIpAddressEditDto editDto) {
        sysDeptIpAddressService.sysEdit(editDto);
        return CommonResult.success();
    }

    /**
     * 删除科室IP
     */
    @Log(title = "科室IP", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除科室IP")
    @PreAuthorize("@ss.hasPermi('system:dept:ip:remove')")
    public CommonResult remove(@PathVariable Long[] ids) {
        return CommonResult.success(sysDeptIpAddressService.deleteSysDeptIpAddressByIds(ids));
    }
}
